$(function () {
  var psd1 = document.querySelector('.psd1')
  var psd2 = document.querySelector('.psd2')
  var bdobj = {}
  $('.zhuce').on('click', function () {
    if (psd1.value !== psd2.value) {
      alert('两次输入密码不一致')
    } else {
      const bdstrs = $('#form2').serialize().split('&')
      for (var i = 0; i < bdstrs.length; i++) {
        const start = bdstrs[i].substr(0, bdstrs[i].indexOf('='))
        const end = bdstrs[i].substr(
          bdstrs[i].indexOf('=') + 1,
          bdstrs[i].length
        )
        bdobj[start] = end
      }
      axios({
        method: 'POST',
        url: 'http://big-event-vue-api-t.itheima.net/api/reg',
        data: bdobj,
      })
        .then(({ data: res }) => {
          if (res.code !== 0) {
            alert(res.message)
          } else {
            alert('注册成功')
            location.href = './login.html'
          }
        })
        .catch((error) => {
          console.log(error)
        })
    }
  })
})
